from dataclasses import dataclass, field

@dataclass
class Account:
    balance: int = field(default=0)

    def __post_init__(self):
        if not isinstance(self.balance, int):
            raise TypeError(f'balance must be an integer, got {type(self.balance).__name__}')

# 创建Account类的实例，并尝试传入一个非整数类型的初始余额
try:
    account = Account('100')  # 这里故意传入一个字符串来模拟类型错误
except TypeError as e:
    print(e)

# 正确的创建方式
account = Account(100)
print(f'账户余额 = {account.balance}')
